var pdtv01 = {
  args:[],
  init: function() {
    // init browser information
    this.browser = this.searchString(this.dataBrowser) || "unk browser";
    this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "unk version";
    this.OS = this.searchString(this.dataOS) || "unk OS";
    // read all pairs
    this.readParams();
    // count page to cookie
    this.expDate = this.getNewDate();
    this.cvpg = this.getCookie("_cvpg");
    if(this.cvpg) {
      this.cvpg = parseInt(this.cvpg) + 1;
    }
    else { // new
      this.cvpg = 1;
      this.saveData();
    }
    this.setCookie("_cvpg", this.cvpg, this.expDate);
  },
  getNewDate: function() {
    var date = new Date();
    var skew = new Date(0).getTime();
    if(skew > 0) date.setTime(date.getTime() - skew);
    date.setTime(date.getTime() + 31 * 24 * 60 * 60 * 1000);
    return date;
 },
 getCookie: function(name) {
    var pref = name + "=";
    var startIdx = document.cookie.indexOf(pref);
    if(startIdx == -1) return null;
    var endIdx = document.cookie.indexOf(";", startIdx + pref.length);
    if(endIdx == -1) endIdx = document.cookie.length;
    return unescape(document.cookie.substring(startIdx + pref.length, endIdx));
  },
  setCookie: function(name, val, exp, path, domain, secure) {
    document.cookie = name + "=" + escape(val) +
        (exp ? "; expires=" + exp.toGMTString() : '') +
        (path ? "; path="+path : '') +
        (domain ? "; domain=" + domain : '') +
        (secure ? "; secure" : '');
  },
  deleteCookie: function(name, path, domain) {
    if(this.getCookie(name)) {
        document.cookie = name + "=" + (path ? "; path=" + path : '') + (domain ? "; domain=" + domain : '') + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
  },
  saveData: function() {
    var img = new Image();
    img.src = (("http:" == document.location.protocol) ? "http://" : "https://") + 'www.compuvestb2b.com/WebStatus/sniffertest'
        // main params
        + '?wid=' + this.getWebID()             // website id
        + '&aid=' + this.getParam("advsite", 15)// advert site
        + '&src=' + this.getParam("Search", 29) // search param
        + '&sku=' + this.getParam("sku", 13)    // accware sku
        // addition params
        + '&cvip=' + this.getIP()               // ip address (integer format)
        + '&pg=' + this.cvpg                    // count of page
        + '&rf=' + escape(document.referrer)    // comming from
        + '&url=' + escape(document.location.href)// current url
        + '&page=' + this.getPage()             // current page
        + '&bws=' + this.browser + ':' + this.version + ':' + this.OS;
  },
  getWebID: function() {
    return window._cvid || '0';
  },
  getParam:function(name, ln) {
    var val = this.args[name];
    if(ln) {
      val = val ? (val.length > ln ? val.substring(0, ln) : val) : '';
    }
    return val;
  },
  readParams: function() {
    var idx,pos,url = document.URL;
    if((idx = url.indexOf('?')) > 0) {
      url = url.substring(idx + 1, url.length);
      var pairs = url.split('&');
      for(var i=0; i < pairs.length; i++) {
         pos = pairs[i].indexOf('=');
         if(pos == -1) continue;
         this.args[pairs[i].substring(0, pos)] = escape(pairs[i].substring(pos + 1));
      }
    }
  },
  getIP: function() {
    var ip = window._cvip || '0.0.0.0';
    var arip = ip.split('.');
    return (arip[3] * 1) + (arip[2] * 256) + (arip[1] * 65536) + (arip[0] * 16777216);
  },
  getPage: function() {
    // 1) http://compuvest.com/ -> /
    // 2) http://compuvest.com/Desc.jsp -> /Desc.jsp
    // 3) http://compuvest.com/Desc.jsp?iid=5555 -> /Desc.jsp
    // 4) http://compuvest.com/Desc.jsp;jssessionid=hjsaahsd?iid=5555 -> /Desc.jsp
    var i,h,k,url = document.location.href;
    if((i = url.indexOf("://")) > -1) {
      h = url.substring(i + 3, url.length);
      if(h.indexOf('/') > -1) {
        k = h.substring(h.indexOf('/'), h.length);
        if(k.indexOf('?') > -1) k = k.substring(0, k.indexOf('?'));
        if(k.indexOf(';') > -1) k = k.substring(0, k.indexOf(';'));
      }
    }
    return k;
  },
  searchString: function (data) {
    for(var i=0; i < data.length; i++) {
      var dataString = data[i].string;
      var dataProp = data[i].prop;
      this.versionSearchString = data[i].versionSearch || data[i].identity;
      if(dataString) {
	if(dataString.indexOf(data[i].subString) != -1)
	  return identity = data[i].identity;
	}
	else if(dataProp) {
	  return identity = data[i].identity;
        }
    }
    return '';
 },
 searchVersion: function (dataString) {
    var index = dataString.indexOf(this.versionSearchString);
    if (index == -1) return 0;
    return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
 },
 dataBrowser: [
    { string: navigator.userAgent,  subString: "Chrome",    identity: "Chrome"      },
    { string: navigator.userAgent,  subString: "OmniWeb",   identity: "OmniWeb",    versionSearch: "OmniWeb/"   },
    { string: navigator.vendor,     subString: "Apple",     identity: "Safari",     versionSearch: "Version"    },
    { string: navigator.vendor,     subString: "iCab",      identity: "iCab"        },
    { string: navigator.vendor,     subString: "KDE",       identity: "Konqueror"   },
    { string: navigator.userAgent,  subString: "Firefox",   identity: "Firefox"     },
    { string: navigator.vendor,     subString: "Camino",    identity: "Camino"      },
    { string: navigator.userAgent,  subString: "Netscape",  identity: "Netscape"    },// for newer Netscapes (6+)
    { string: navigator.userAgent,  subString: "MSIE",      identity: "Explorer",   versionSearch: "MSIE"   },
    { string: navigator.userAgent,  subString: "Gecko",     identity: "Mozilla",    versionSearch: "rv" },
    { string: navigator.userAgent,  subString: "Mozilla",   identity: "Netscape",   versionSearch: "Mozilla" },// for older Netscapes (4-)
    { prop: window.opera,                                   identity: "Opera"       }
 ],
 dataOS: [
    { string: navigator.platform,   subString: "Win",   identity: "Windows"     },
    { string: navigator.platform,   subString: "Mac",   identity: "Mac"         },
    { string: navigator.userAgent,  subString: "iPhone",identity: "iPhone/iPod" },
    { string: navigator.platform,   subString: "Linux",	identity: "Linux"       }
 ]
};
pdtv01.init();

/*
 var PDt = {
 init:function() {
  this.browser = this.searchString(this.dataBrowser) || 0;
  this.version = (this.getVersion(navigator.userAgent) || this.getVersion(navigator.appVersion)) || 0;
  this.OS = this.searchString(this.dataOS) || 0;
  this.BWS = (this.browser * 1) + (this.version * 256) + (this.OS * 65536);
  this.nextmonth = this.getNewDate();
  this.newmfr = false;
  this.newcook = false;
  this.searchParams();
  this.makeCookie();
  this.fst = true;
  this.cv_polls = 0;
  this.cv_poll = 10000;
  this.cvtrack();
 },
 getIP:function() {
  var addr = window._cvip || '0.0.0.0';
  var arip = addr.split('.');
  return (arip[3] * 1) + (arip[2] * 256) + (arip[1] * 65536) + (arip[0] * 16777216);
 },
 getPage:function() {
 // 1) http://www.compuvest.com/ -> /
 // 2) http://www.compuvest.com/Desc.jsp -> /Desc.jsp
 // 3) http://www.compuvest.com/Desc.jsp?iid=5555 -> /Desc.jsp
 // 4) http://www.compuvest.com/Desc.jsp;jssessionid=hjsaahsd?iid=5555 -> /Desc.jsp
 var i,h,k,url = document.location.href;
 if((i = url.indexOf("://")) > -1){
  h = url.substring(i + 3, url.length);
  if(h.indexOf('/') > -1){
   k = h.substring(h.indexOf('/'), h.length);
   if(k.indexOf('?') > -1) k = k.substring(0, k.indexOf('?'));
   if(k.indexOf(';') > -1) k = k.substring(0, k.indexOf(';'));
  }
 }
 return k;
 },
 getID:function() {
   return window._cvid || '0';
 },
 getParam:function(name, ln) {
   var val = this.args[name];
   if(ln) {
     val = val ? (val.length > ln ? val.substring(0, ln) : val) : '';
   }
   return val;
 },
 searchParams: function() {
  var idx,pos,url = document.URL;
  if((idx = url.indexOf('?')) > 0) {
   url = url.substring(idx + 1, url.length);
   var pairs = url.split('&');
   for(var i=0; i < pairs.length; i++) {
    pos = pairs[i].indexOf('=');
    if(pos == -1) continue;
    this.args[pairs[i].substring(0, pos)] = escape(pairs[i].substring(pos + 1));
   }
  }
 },
 searchString:function(data) {
  for(var i=0; i < data.length; i++) {
   var dataStr = data[i].nvg;
   this.versionStr = data[i].versionSearch || data[i].nm;
   if(dataStr && dataStr.indexOf(data[i].subStr) != -1){
       return data[i].nm;
   }
  }
  return 0;
 },
 getVersion:function(dataString){
  var idx = dataString.indexOf(this.versionStr);
  if(idx == -1) return 0;
  return parseInt(dataString.substring(idx + this.versionStr.length + 1));
 },
 dataBrowser:[
  {nvg:navigator.userAgent,subStr:"MSIE",versionSearch:"MSIE",nm:1},
  {nvg:navigator.userAgent,subStr:"Firefox",nm:2},
  {nvg:navigator.userAgent,subStr:"Chrome",nm:3},
  {nvg:navigator.userAgent,subStr:"OmniWeb",versionSearch:"OmniWeb/",nm:4},
  {nvg:navigator.vendor,subStr:"Apple",versionSearch: "Version",nm:5},
  {nvg:navigator.userAgent,subStr:"Opera",nm:6},
  {nvg:navigator.vendor,subStr: "iCab",nm:7},
  {nvg:navigator.vendor,subStr:"KDE",nm:8},
  {nvg:navigator.vendor,subStr:"Camino",nm:9},
  {nvg:navigator.userAgent,subStr:"Netscape",nm:10},
  {nvg:navigator.userAgent,subStr:"Mozilla",versionSearch:"Mozilla",nm:10},
  {nvg:navigator.userAgent,subStr:"Gecko",versionSearch:"rv",nm:11}
 ],
 dataOS:[
  {nvg:navigator.platform,subStr:"Win",nm:1},
  {nvg:navigator.platform,subStr:"Linux",nm:2},
  {nvg:navigator.platform,subStr:"Mac",nm:3},
  {nvg:navigator.userAgent,subStr:"iPhone",nm:4}
 ],
 args:[],
 getNewDate: function() {
 var date = new Date();
 var skew = new Date(0).getTime();
 if(skew > 0) date.setTime(date.getTime() - skew);
 date.setTime(date.getTime() + 31 * 24 * 60 * 60 * 1000);
 return date;
},
getCookie: function(name) {
  var prefix = name + "=";
  var cookieStartIndex = document.cookie.indexOf(prefix);
  if(cookieStartIndex == -1) return null;
  var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
  if(cookieEndIndex == -1) cookieEndIndex = document.cookie.length;
  return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
 },
 setCookie: function(name, val, exp, path, domain, secure) {
  document.cookie = name + "=" + escape(val) +
     (exp ? "; expires=" + exp.toGMTString() : '') +
     (path ? "; path="+path : '') +
     (domain ? "; domain=" + domain : '') +
     (secure ? "; secure" : '');
 },
 deleteCookie: function(name, path, domain) {
  if(this.getCookie(name)) {
   document.cookie = name + "=" + (path ? "; path=" + path : '') + (domain ? "; domain=" + domain : '') + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
 },
 makeCookie: function() {
  var val = this.getParam("Search", 30);
  if(val) {
    var mfr = this.getCookie("_cvmfr");
    if(!mfr || val != mfr) {
     this.newmfr = true;
     this.setCookie("_cvmfr", val, this.nextmonth);
   }
  }

  // page to cookie
  this.cvpg = this.getCookie("_cvpg");
  this.cvpg = this.cvpg ? parseInt(this.cvpg) + 1 : 1;
  this.setCookie("_cvpg", this.cvpg, this.nextmonth);

  // id to cookie
  this.sid = this.getCookie("_cvsid");
  if(!this.sid) {
   this.newcook = true;
   this.sid = Math.floor(Math.random() * 1000000000);
  }
  this.setCookie("_cvsid", this.sid, this.nextmonth);
 },
 cvtrack: function() {
  if(++this.cv_polls > 180) return;

 var cvnw = new Date().getTime();
 var vm_ref = '';
 if(this.fst && this.newcook || this.newmfr) {
   this.fst = !this.fst;
   vm_ref = '&rf=' + escape(document.referrer)
        + '&bws=' + this.BWS
        + '&adv=' + this.getParam("advsite", 15)
        + '&srch=' + this.getParam("Search", 29)
        + '&sku=' + this.getParam("sku", 13);
 }
 var img = new Image();
 img.src = (("http:" == document.location.protocol) ? "http://" : "https://") + 'www.compuvestb2b.com/WebStatus/sniffertest?id='
     + cvnw
     + '&wid=' + this.getID()
     + '&cvip=' + this.getIP()
     + '&sid=' + this.sid
     + '&pg=' + this.cvpg
     + vm_ref
     + '&url=' + escape(document.location.href)
     + '&page=' + this.getPage();
 }
};
PDt.init();
*/